package com.light.springboot.base.jpa.service.support;

import com.light.springboot.base.jpa.repostitory.utils.SearchFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;


public interface GenericService<E, PK extends Serializable> {

    <S extends E> S save(S entity) throws Exception;

    int save(Iterable<? extends E> entities) throws Exception;

    <S extends E> S update(S entity) throws Exception;

    void delete(PK id) throws Exception;

    void delete(E entity) throws Exception;

    void delete(Iterable<? extends E> entities) throws Exception;

    void deleteAll() throws Exception;

    boolean exists(PK id);

    long count();

    long count(Specification<E> spec);

    E find(PK id);

    E find(Specification<E> spec);

    List<E> findAll();

    List<E> findAll(Sort sort);

    List<E> findAll(Iterable<PK> ids);

    List<E> findAll(Specification<E> spec);

    List<E> findAll(Collection<SearchFilter> filters);

    Page<E> findAll(Specification<E> spec, Pageable pageable);

    Page<E> findAll(Collection<SearchFilter> filters, Pageable pageable);

    Page<E> findAll(Specification<E> spec, Sort sort, Pageable pageable);

    List<E> findAll(Specification<E> spec, Sort sort);

	int update(Iterable<? extends E> entities) throws Exception;
}

